package com.zmn.plat.admin;

import com.github.ltsopensource.spring.boot.annotation.EnableJobClient;
import com.zmn.framework.web.config.FastJsonHttpMessageConverterConfiguration;
import com.zmn.manager.common.database.config.OneMasterMultiSlaveDataSourceConfiguration;
import com.zmn.manager.mq.annotation.EnableMQSend;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

/**
 * @author nowind
 * @since 2018/9/5 12:44
 */
@SpringBootApplication(scanBasePackages = {"com.zmn.plat", "com.zmn.manager.common"}, exclude = {DataSourceAutoConfiguration.class, ElasticsearchDataAutoConfiguration.class, RestClientAutoConfiguration.class})
@EnableCaching
@EnableJobClient
@EnableTransactionManagement
@Import({OneMasterMultiSlaveDataSourceConfiguration.class, FastJsonHttpMessageConverterConfiguration.class})
@EnableMQSend
//@PropertySource(value = "file:/a/config-repo/plat/admin.properties", ignoreResourceNotFound = true, encoding = "UTF-8")
public class AdminApplication {

    public static void main(String[] args) {
        try {
            System.setProperty("es.set.netty.runtime.available.processors", "false");
            SpringApplication.run(AdminApplication.class, args);
        } catch (Exception e) {

        }
    }


    @SuppressWarnings("Duplicates")
    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setDefaultEncoding("UTF-8");
        // resolveLazily属性启用是为了推迟ZsNormalOrderWorkAmountBServiceImplZsNormalOrderWorkAmountBServiceImpl文件解析，以在在UploadAction中捕获文件大小异常
        resolver.setResolveLazily(true);
        resolver.setMaxInMemorySize(40960);
        // 上传文件大小 50M 50*1024*1024
        resolver.setMaxUploadSize(50 * 1024 * 1024);
        return resolver;
    }


}

